package org.elephas.webapp.frontend.component;

import org.apache.wicket.datetime.markup.html.basic.DateLabel;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.CompoundPropertyModel;
import org.elephas.model.Post;
import org.elephas.webapp.frontend.component.links.BookmarkableBlogLink;
import org.elephas.webapp.frontend.component.links.BookmarkableBlogPostLink;
import org.elephas.webapp.model.DetachableBlogModel;
import org.elephas.webapp.model.DetachablePostModel;

/**
 * This panel basically renders the title, creation date, category, blog name,
 * posted by and the excerpt.
 * 
 * @author Gerolf Seitz
 * 
 */
public class PostPreviewPanel extends Panel {
	private static final long serialVersionUID = 1L;

	/**
	 * Constructs the {@link PostPreviewPanel}
	 * 
	 * @param id
	 *            the component id
	 * @param model
	 *            the model representing the {@link Post}
	 */
	public PostPreviewPanel(String id, DetachablePostModel model) {
		super(id, new CompoundPropertyModel(model));

		final Post post = model.getObject();		

		add(new BookmarkableBlogPostLink("title", model));
		add(DateLabel.forDateStyle("created", "L-"));
		add(new Label("excerpt"));
		add(new CategoriesLabel("categories"));
		add(new Label("user"));
		add(new BookmarkableBlogLink("blog.name", new DetachableBlogModel(post
				.getBlog())));
	}
}
